package com.example.easyutils.food;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.easyutils.R;

import java.util.List;
import java.util.Map;

public class StepRecycleView extends RecyclerView.Adapter {

    List mlist;
    Context context;
    public StepRecycleView(List processList, Context context) {
        Log.d("listst",processList+"");
        mlist = processList;
        this.context = context;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.cook_process_item,
                parent,false);
        StepRecycleView.ViewHolder viewHolder = new StepRecycleView.ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        Log.d("positioncode",position+"");
        Log.d("positioncodeList",mlist.get(position)+"");
        if(holder instanceof StepRecycleView.ViewHolder) {
            ((StepRecycleView.ViewHolder) holder).cookStep.setText(((Map)mlist.get(position)).get("pcontent").toString());
//            ((StepRecycleView.ViewHolder) holder).imageStep.setAdapter();
            Glide
                    .with(context)
                    .load(((Map)mlist.get(position)).get("pic"))
                    .into(((StepRecycleView.ViewHolder) holder).imageStep);
        }
    }

    @Override
    public int getItemCount() {
        Log.d("listLength",mlist.size()+"");
        return mlist.size();
    }


    //自定义的ViewHolder，持有每个Item的的所有界面元素
    class ViewHolder extends RecyclerView.ViewHolder {
        public TextView cookStep;
        public ImageView imageStep;
        public ViewHolder(View view) {
            super(view);
            cookStep = view.findViewById(R.id.text_step);
            imageStep = view.findViewById(R.id.image_step);
//            mlinearLayout = view.findViewById(R.id.mLinearLayout);
        }
    }
}
